package top.stacktrace.account.dao;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import top.stacktrace.account.domain.User;

import java.util.List;

@Component
@Mapper
public interface AccountDao {
    // 增加余额值
    @Update("update user set balance=balance+#{b} where id=#{id}")
    int inCreaseBalance(long id,long b);

    // 减少余额(判断不能扣负)
    @Update("update user set balance=balance-#{b} where id=#{id} and balance>=#{b}")
    int deCreaseReserve(long id,long b);

    // 设置用户余额值
    @Update("update user set balance=#{b} where id=#{id}")
    int setBalance(long id,long b);

    @Select("select * from user")
    List<User> getUsers();

    @Select("select * from user where id=#{id}")
    User getUserById(long id);

    @Select("select * from user where name=#{name}")
    User getUserByName(String name);

    @Insert("insert into xalog (xid,service) values(#{xid},'account')")
    int saveXA(String xid);

    @Select("select count(1) from xalog where xid=#{xid} and service='account'")
    int countXA(String xid);

    @Delete("delete from xalog where xid=#{xid} and service='account'")
    int delXA(String xid);
}
